<template>
  <div class="RevenueRecords">
    <van-list
      v-model="data[active].loading"
      :finished="data[active].finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="RevenueRecords_cont">
        <p>总现金额</p>
        <p>{{ $common.formatMoney(price.sumAmount) }}</p>
      </div>
      <!-- 图标 -->
      <van-row class="RevenueRecords_icon" gutter="10">
        <van-col span="12">
          <div class="RevenueRecords_icon_item">
            <h2><img src="@/assets/MyWallet_icon.png" /> 分享佣金</h2>
            <h2>{{ $common.formatMoney(price.shareAmount) }}</h2>
          </div>
        </van-col>
        <van-col span="12">
          <div class="RevenueRecords_icon_item">
            <h2><img src="@/assets/MyWallet_icon1.png" /> 卖货金额</h2>
            <h2>{{ $common.formatMoney(price.sellAmount) }}</h2>
          </div>
        </van-col>
      </van-row>
      <!-- 提现列表 -->
      <van-tabs v-model="active" sticky color="#D4B066">
        <van-tab title="佣金">
          <ul v-if="data[active].list.length > 0">
            <li
              class="RevenueRecords_item"
              v-for="(item, index) in data[active].list"
              :key="index"
            >
              <van-row>
                <van-col span="6">
                  <img src="@/assets/yongjin.png" />
                </van-col>
                <van-col span="18">
                  <div class="RevenueRecords_item_name">
                    <h3>+{{ $common.formatMoney(item.amount) }}</h3>
                    <p>{{ $common.getExactTime(item.createTime) }}</p>
                  </div>
                </van-col>
              </van-row>
            </li>
          </ul>
          <van-empty v-else />
        </van-tab>
        <van-tab title="商品">
          <ul v-if="data[active].list.length > 0">
            <li
              class="RevenueRecords_item"
              v-for="(item, index) in data[active].list"
              :key="index"
            >
              <van-row>
                <van-col span="6">
                  <img src="@/assets/shangpin.png" />
                </van-col>
                <van-col span="18">
                  <div class="RevenueRecords_item_name">
                    <h3>+{{ $common.formatMoney(item.amount) }}</h3>
                    <p>{{ $common.getExactTime(item.createTime) }}</p>
                  </div>
                </van-col>
              </van-row>
            </li>
          </ul>
          <van-empty v-else />
        </van-tab>
      </van-tabs>
    </van-list>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Col, Row, List, Button, Empty, Tabs, Tab } from "vant";
Vue.use(Empty);
Vue.use(List);
Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Col);
Vue.use(Row);
Vue.use(Button);
@Component({})
export default class RevenueRecords extends Vue {
  private active: number = 0;
  private data = [
    {
      form: {
        page: 1,
        size: 20,
        typ: [3, 4],
      },
      loading: false,
      finished: false,
      list: [],
    },
    {
      form: {
        page: 1,
        size: 20,
        typ: [1],
      },
      loading: false,
      finished: false,
      list: [],
    },
  ];

  private price = {
    sumAmount: 0,
    shareAmount: 0,
    sellAmount: 0,
  };

  private onLoad() {
    this.$common.getAuthToken(this.getData);
  }
  private getData() {
    this.$post(`gainDetail`, this.data[this.active].form).then((res: any) => {
      if (res.code == 0) {
        this.data[this.active].loading = false;
        this.data[this.active].list = this.data[this.active].list.concat(
          res.data.list
        );
        this.price.sumAmount = res.data.sumAmount;
        this.price.sellAmount = res.data.sellAmount;
        this.price.shareAmount = res.data.shareAmount;
        this.data[this.active].form.page += 1;
        if (res.data.list.length < 20) {
          this.data[this.active].finished = true;
        }
      } else {
        this.data[this.active].finished = true;
      }
    });
  }
}
</script>

<style lang="scss" scope>
.RevenueRecords {
  width: 100%;
  padding: 30px 15px;
  box-sizing: border-box;
  margin-bottom: 100px;
  .RevenueRecords_cont {
    width: 100%;
    height: 200px;
    border-radius: 15px;
    background-image: url("~@/assets/MyWallet.png");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    padding: 50px;
    box-sizing: border-box;
    p {
      font-size: 36px;
      font-weight: 300;
      color: #ffffff;
      line-height: 1.3;
    }
  }
  .RevenueRecords_icon {
    padding: 30px 0;
    .RevenueRecords_icon_item {
      border-radius: 20px;
      border: 1px solid #cdcdcd;
      text-align: center;
      padding: 30px;
      box-sizing: border-box;
      h2 {
        font-size: 30px;
        font-weight: 300;
        color: #333333;
        line-height: 1.5;
        img {
          width: 40px;
          display: inline-block;
          vertical-align: text-bottom;
        }
      }
    }
  }
  .RevenueRecords_title {
    font-size: 35px;
    line-height: 1.5;
    padding-left: 10px;
    border-left: 5px solid #b99267;
    box-sizing: border-box;
    font-weight: normal;
    margin: 20px 15px;
  }
  ul {
    list-style: none;
    width: 100%;
    .RevenueRecords_item {
      width: 100%;
      padding: 20px;
      box-sizing: border-box;
      background-color: #fff;
      margin-bottom: 20px;
      img {
        width: 100%;
        height: 110px;
        display: block;
        border-radius: 10px;
      }
      .RevenueRecords_item_name {
        width: 100%;
        padding-left: 20px;
        box-sizing: border-box;
        & > h3 {
          font-size: 30px;
          font-weight: 400;
          color: #000000;
          line-height: 2;
        }
        & > p {
          font-size: 24px;
          font-weight: 300;
          color: #343434;
          line-height: 2;
        }
      }
    }
  }
}
</style>
